<!DOCTYPE html>
<html class="loginHtml">
<head>
	<meta charset="utf-8">
	<title>登录</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" href="#(CONTEXT_PATH)/logo.gif">
	<link rel="stylesheet" href="#(CONTEXT_PATH)/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="#(CONTEXT_PATH)/css/public.css" media="all" />
</head>
<body class="loginBody">
	<form class="layui-form" id="loginForm">
		<div class="login_face"><img src="#(CONTEXT_PATH)/images/logo.gif" class="userAvatar"></div>
		<div class="layui-form-item input-item">
			<label for="userName">用户名</label>
			<input type="text" placeholder="请输入用户名" autocomplete="off" id="userName" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item">
			<label for="password">密码</label>
			<input type="password" placeholder="请输入密码" autocomplete="off" id="password" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item" id="imgCode">
			<label for="code">验证码</label>
			<input type="text" placeholder="请输入验证码" autocomplete="off" id="code" class="layui-input" lay-verify="required">
			<img src="createImage" alt="点击更换验证码" onclick="changeCode()" id="codeImg">
		</div>
		<div class="layui-form-item">
			<button class="layui-btn layui-block" lay-filter="login" lay-submit id="login">登录</button>
		</div>
		<div class="layui-form-item">
			<p style="text-align: center;">2020 © HaoHU license</p>
		</div>
	</form>
	<script type="text/javascript" src="#(CONTEXT_PATH)/layui/layui.js"></script>
	<script type="text/javascript">
	function changeCode(){
		document.getElementById("codeImg").src = "createImage?v=" + new Date().getTime();
		$("#code").val("");
	}
	
	layui.use(['form','layer','jquery'],function(){
	    var form = layui.form,
	        layer = parent.layer === undefined ? layui.layer : top.layer
	        $ = layui.jquery;

	    //登录按钮
	    form.on("submit(login)",function(data){
	        $(this).text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
	        setTimeout(function(){
		      	  $.ajax({
		    		  url: 'doLogin',
		    		  data: {"userName":$("#userName").val(),"password":$("#password").val(),"code":$("#code").val()},
		    		  dataType: 'json',
		    		  type: 'post',
		    		  success: function(responseM){
		    			  if(responseM.flag){
		    				  window.sessionStorage.setItem("USER_ID",responseM.USER_ID);
		    				  window.sessionStorage.setItem("NAME",responseM.NAME);
		    				  window.sessionStorage.setItem("ROLE",responseM.ROLE);
		    				  window.location.href = "#(CONTEXT_PATH)/index.html";
		    			  } else {
		    				  layer.msg(responseM.msg,{icon: 2,time:1000},function(){
		    					  $("#login").text("登录").removeAttr("disabled").removeClass("layui-disabled");
		    					  changeCode();
		    				  });
		    			  }
		    		  },
		    	  	  error: function(){
		    	  		  layer.msg('信息提交失败！',{icon: 2,time:1000},function(){
	    					  $("#login").text("登录").removeAttr("disabled").removeClass("layui-disabled");
	    					  changeCode();
		    	  		  });
		    	  	  }
	    	  });
	        },1000);
	        return false;
	    });

	    //表单输入效果
	    $(".loginBody .input-item").click(function(e){
	        e.stopPropagation();
	        $(this).addClass("layui-input-focus").find(".layui-input").focus();
	    })
	    $(".loginBody .layui-form-item .layui-input").focus(function(){
	        $(this).parent().addClass("layui-input-focus");
	    })
	    $(".loginBody .layui-form-item .layui-input").blur(function(){
	        $(this).parent().removeClass("layui-input-focus");
	        if($(this).val() != ''){
	            $(this).parent().addClass("layui-input-active");
	        }else{
	            $(this).parent().removeClass("layui-input-active");
	        }
	    })
	});
	</script>
</body>
</html>